// sqlite demo

package main

import (
	"database/sql"
	"fmt"
	"log"

	_ "github.com/mattn/go-sqlite3"
)

func main() {
	fmt.Println("start")
	db, err := sql.Open("sqlite3", "gee.db")
	if err != nil {
		panic(err)
	}

	defer func() { _ = db.Close() }()

	_, err = db.Exec("DROP TABLE IF EXISTS User;")
	if err != nil {
		panic(err)
	}

	_, err = db.Exec("CREATE TABLE User(Name text);")
	if err != nil {
		panic(err)
	}

	fmt.Println("step1")

	result, err := db.Exec("INSERT INTO User(`Name`) VALUES (?), (?)", "Tom", "Sam")
	if err == nil {
		affected, _ := result.RowsAffected()
		log.Println(affected)
	} else {
		panic(err)
	}

	row := db.QueryRow("SELECT Name FROM User LIMIT 1")
	var name string
	if err := row.Scan(&name); err == nil {
		log.Println(name)
	}
}
